<?php
namespace Admin\Model;
use Think\Model;
class SystemModel extends Model{

    protected $trueTableName = 'user';

    protected $_validate = array(

        array('oldpassword','require','老密码必须填写！'),

        array('oldpassword','checkPwd','老密码不正确',1,'callback'),

        array('password','5,20','请输入5-20位新密码！',1,'length'), // 当值不为空的时候判断是否在一个范围内

        array('password','checkPwd2','新密码与老密码一样',1,'callback'),

        array('password2','password','确认密码不正确',1,'confirm'), // 验证确认密码是否和密码一致

    );

    protected function checkPwd($oldpassword){
        //echo $oldpassword;
        return substr(md5($oldpassword),5,-5)==$_SESSION['user']['password'];
    }
    protected function checkPwd2($password){
        $a = substr(md5($password),5,-5)==$_SESSION['user']['password']?false:true;
        return $a;
    }

    protected $_auto = array (
        array('id','getId',3,'callback'),
        array('email','getEmail',3,'callback'),
        array('password','getPassword',3,'callback') ,
        array('token','getToken',3,'callback'),
    );

    protected function getId(){
        return $_SESSION['user']['id'];
    }
    protected function getEmail(){
        return $_SESSION['user']['email'];
    }

    protected function getPassword($password){

        //echo $password;
        return substr(md5($password),5,-5);
    }

    protected function getToken(){
        return uniqid();
    }

//    public function getUserData(){
//        $array=array();
//        $array['email']=$_SESSION['user']['email'];
//        $array['password']=substr(md5(I('post.password')),5,-5);
//        $array['token']=uniqid();
//        return $array;
//}

}